package com.ruoyi.life.service.impl;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.life.mapper.FeFineMapper;
import com.ruoyi.life.service.IFeFineService;
import com.ruoyi.omp.api.domain.FeFine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 违约金Service业务层处理
 *
 * @author cjie
 * @date 2021-09-23
 */
@Service
public class FeFineServiceImpl implements IFeFineService {
    @Autowired
    private FeFineMapper feFineMapper;

    /**
     * 查询违约金
     *
     * @param id 违约金ID
     * @return 违约金
     */
    @Override
    public FeFine selectFeFineById(String id) {
        return feFineMapper.selectFeFineById(id);
    }

    /**
     * 查询违约金列表
     *
     * @param feFine 违约金
     * @return 违约金
     */
    @Override
    public List<FeFine> selectFeFineList(FeFine feFine) {
        return feFineMapper.selectFeFineList(feFine);
    }

    /**
     * 新增违约金
     *
     * @param feFine 违约金
     * @return 结果
     */
    @Override
    public int insertFeFine(FeFine feFine) {
        feFine.setId(IdUtil.getSnowflake(0, 0).nextIdStr());
        feFine.setCreateTime(DateUtils.getNowDate());
        feFine.setCreateBy(SecurityUtils.getUsername());
        return feFineMapper.insertFeFine(feFine);
    }

    /**
     * 修改违约金
     *
     * @param feFine 违约金
     * @return 结果
     */
    @Override
    public int updateFeFine(FeFine feFine) {
        feFine.setUpdateTime(DateUtils.getNowDate());
        feFine.setUpdateBy(SecurityUtils.getUsername());
        return feFineMapper.updateFeFine(feFine);
    }

    /**
     * 批量删除违约金
     *
     * @param ids 需要删除的违约金ID
     * @return 结果
     */
    @Override
    public int deleteFeFineByIds(String[] ids) {
        return feFineMapper.deleteFeFineByIds(ids);
    }

    /**
     * 删除违约金信息
     *
     * @param id 违约金ID
     * @return 结果
     */
    @Override
    public int deleteFeFineById(String id) {
        return feFineMapper.deleteFeFineById(id);
    }

    @Override
    public FeFine listLastFine(String billId) {
        return feFineMapper.listLastFine(billId);
    }
}
